home *** CD-ROM | disk | FTP | other *** search
- /*
- File: OSAHelpers.h
-
- Contains: Functions to help you when you are working with the OSA.
-
- Written by: Andy Bachorski
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/21/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- #if PRAGMA_ONCE
- #pragma once
- #endif
-
- #ifndef _OSA_HELPERS_
- #define _OSA_HELPERS_
-
-
- //******************************************************************************
- // A private conditionals file to setup the build environment for this project.
-
- #include "PrivateConditionals.h"
-
-
- //********** Universal Headers ****************************************
-
- #include <AppleScript.h>
- #include <Components.h>
- #include <Files.h>
- #include <OSA.h>
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #if PRAGMA_IMPORT
- #pragma import on
- #endif
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=mac68k
- #elif PRAGMA_STRUCT_PACKPUSH
- #pragma pack(push, 2)
- #elif PRAGMA_STRUCT_PACK
- #pragma pack(2)
- #endif
-
- //******************************************************************************
-
- #define EVENPAD(ptr) ( ( (ptr) + 1 ) & 0xfffffffe )
-
-
- enum {
- kScriptResID = 128
- };
-
-
-
- #define kHandlerNameHeaderSize 8 // The size of everything before name below
-
- struct HandlerNameList {
- DescType nameType;
- long nameLength;
- char name[1]; // variable length, not terminated
- };
- typedef struct HandlerNameList HandlerNameList;
- typedef HandlerNameList *HandlerNameListPtr;
-
-
- //******************************************************************************
-
- pascal Boolean OSAHAppleScriptIsPresent( void );
- /*
- Checks for the presence of the AppleScript OSA component.
-
- RESULT CODES
- ____________
- true AppleScript is present and available
- false It isn't
- ____________
- */
-
- //******************************************************************************
-
- pascal OSErr OSAHOpenGenericScriptingComponent( ComponentInstance *compInstPtr );
- /*
- Open the default scripting component.
-
- componentInstance input: Pointer to ComponentInstance variable.
- output: The newly opened scripting component, or nil if error.
-
- RESULT CODES
- ____________
- noErr 0 No error
- errOSACantOpenComponent -1762 Can't connect to scripting system with that ID
- ____________
- */
-
- //******************************************************************************
-
- pascal OSErr OSAHOpenAppleScriptComponent( ComponentInstance *compInstPtr );
- /*
- Open the ApppleScript scripting component.
-
- componentInstance input: Pointer to ComponentInstance variable.
- output: The newly opened scripting component, or nil if error.
-
- RESULT CODES
- ____________
- noErr 0 No error
- errOSACantOpenComponent -1762 Can't connect to scripting system with that ID
- ____________
- */
-
- //******************************************************************************
-
- pascal OSErr OSAHLoadScriptResource( ComponentInstance componentInstance,
- short resFileRef,
- short scriptResID,
- OSAID *scriptIDPtr );
- /*
- Load a script resource for the given component instance.
-
- componentInstance input: Component instance to load script into.
- resFileRef input: Resource file to get script from.
- scriptResID input: Script (type 'scpt') resource ID to load.
- scriptIDPtr input: Pointer to OSAID to return the loaded script ID in.
- output: The newly loaded script ID.
-
- RESULT CODES
- ____________
- noErr 0 No error
- resNotFound -192 Can't find the requested resource
- errOSACorruptData -1702 Corrupt data
- errOSASystemError -1750 General scripting system error
- errOSABadStorageType -1752 Script data not for this scripting component
- errOSADataFormatObsolete -1758 Data format is obsolete
- errOSADataFormatTooNew -1759 Data format is too new
- badComponentInstance $80008001 Invalid component instance
- ____________
- */
-
- //******************************************************************************
-
- pascal OSErr OSAHUnloadScriptResource( ComponentInstance componentInstance,
- short resFileRef,
- short scriptResID,
- OSAID scriptID );
- /*
- Dispose of a script for the given component instance. If there have been
- changes to the script, it is saved before being unloaded.
-
-
- componentInstance input: Component instance to load script into.
- resFileRef input: Resource file to get script from.
- scriptResID input: Script (type 'scpt') resource ID to load.
- scriptIDPtr input: OSAID to return the loaded script ID in.
-
- RESULT CODES
- ____________
- noErr 0 No error
- memFullErr -108 Not enough memory
- nilHandleErr -109 NIL master pointer
- memWZErr -111 Attempt to operate on a free block
- resNotFound -192 Can't find the requested resource
- resAttrErr –198 Attribute inconsistent with operation
- errOSASystemError -1750 General scripting system error
- errOSAInvalidID -1751 Invalid script ID
- errOSABadStorageType -1752 Desired type not supported by this scripting component
- errOSABadSelector -1754 Selector value not supported by scripting component
- badComponentInstance $80008001 Invalid component instance
- ____________
- */
-
- // *****************************************************************************
-
- pascal OSAError OSAHGetHandlerNames( ComponentInstance compInst, OSAID scriptID, AEDescList* handlerListPtr );
- /*
- Given an AppleScript script ID, return an list containing the names of all
- handlers inplemented in the script.
-
- NOTE: Valid only for AppleScript scripts.
-
- Esentially a wrapper around OSAGetHandlerNames() that allows you to pass in either
- a generic or AppleScript component instance.
-
- Returns a list of handler names (typeChar)
-
- The handler name for subroutines, sometimes called named handlers, for should be of
- typeChar and be in cononical form, i.e., all lower case with diacriticals removed.
- The name of a handler for a standard event (run, open, or «event xxxxyyyy») will be
- 8 characters long, and will be of the form clasIDID where 'clas' is the event class
- and 'IDID' is the eventID.
-
-
- compInst input: A generic or AppleScript component instance.
- scriptID input: The script to get the handler names from.
- nameDescPtr input: A list to contain the handler names.
-
- RESULT CODES
- ____________
- ____________
- */
-
- // *****************************************************************************
-
- pascal Boolean OSAHHandlerIsInHandlerList( const AEDescList *handlerListPtr, const AEDesc *nameDescPtr );
- /*
- Look for a particular handler name in a list of handler names (as returned by OSAHGetHandlerNames()).
-
- The handler name for subroutines, sometimes called named handlers, for should be of
- typeChar and be in cononical form, i.e., all lower case with diacriticals removed.
- The name of a handler for a standard event (run, open, or «event xxxxyyyy») will be
- 8 characters long, and will be of the form clasIDID where 'clas' is the event class
- and 'IDID' is the eventID.
-
- NOTE: Valid only for AppleScript scripts.
-
- handlerListPtr input: The list of handler names for an AppleScript script.
- resFileRef input: The handler name to check for, in cononical form.
- nameDescPtr input: An string containing the name of the handler to look for
-
- RESULT CODES
- ____________
- ____________
- */
-
- // *****************************************************************************
-
- pascal Boolean OSAHScriptHasHandler( ComponentInstance compInst, OSAID scriptID, const AEDesc *nameDescPtr );
- /*
- Check a script to see if it contains a particular handler.
-
- The handler name for subroutines, sometimes called named handlers, for should be of
- typeChar and be in cononical form, i.e., all lower case with diacriticals removed.
- The name of a handler for a standard event (run, open, or «event xxxxyyyy») will be
- 8 characters long, and will be of the form clasIDID where 'clas' is the event class
- and 'IDID' is the eventID
-
- For subroutines, the input should be of type 'text' with the dataHandle
- containing a lowercased name for AppleScript english scripts
- For other event handlers (open, quite, «event clasIDID») the input should
- be of type 'evnt' with the data handle containing the event class and ID
- DescTypes, i.e., 8 bytes of the form [clasIDID]
-
- componentInstance input: Component instance for script.
- resFileRef input: Script to get names from.
- nameDescPtr input: A typeChar desc containing the name of the handler to look for
- Note: Must be in cononical form, i.e., 'MyHandler' would be 'myhandler'.
-
- Returns a boolean indicating if the handler was found.
-
- RESULT CODES
- ____________
- ____________
- */
-
- //******************************************************************************
-
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #elif PRAGMA_STRUCT_PACKPUSH
- #pragma pack(pop)
- #elif PRAGMA_STRUCT_PACK
- #pragma pack()
- #endif
-
- #ifdef PRAGMA_IMPORT_OFF
- #pragma import off
- #elif PRAGMA_IMPORT
- #pragma import reset
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif // _OSA_HELPERS_
-